<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>测试页面</title>

    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
</head>
<body>

<form id="loginForm" method="post">
    <input type="text" name="mobile" placeholder="输入手机号" required="true"><br>
    <input type="password" name="password" placeholder="输入密码" required="true"><br>
    <input type="submit" id="btnLogin" value="登录" onclick="login()">
</form>
</body>
<script>
    function login() {
        //表单验证
        $("#loginForm").validate({
            submitHandler: function (form) {
                doLogin();
            }
        })
    }


    //ajax登录
    function doLogin() {
        g_showLoading();

        var inputPass = $("input[name='password']").val();
        var salt = g_passsword_salt;
        var ciphertext = salt.charAt(0) + salt.charAt(2) + inputPass + salt.charAt(5) + salt.charAt(4);
        //将输入密码使用密文传输
        var encodePassword = md5(ciphertext);
        console.log("-->>encodePassword=" + encodePassword);

        $.ajax({
            url: "/login/do_login",
            type: 'POST',
            data: {
                mobile: $("input[name='mobile']").val(),
                password: encodePassword
            },
            success: function (data) {
                layer.closeAll();
                if (data.code === 0) {
                    layer.msg("成功！");
                    window.location.href = "/goods/to_list"
                } else {
                    //弹出异常信息提示
                    layer.msg(data.msg);
                }
            },
            error: function () {
                layer.closeAll();
            }
        });
    }
</script>
</html>

